package com.block.common.vo;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.block.common.enums.AppRspCodeEnum;

import java.util.List;
import java.util.Map;

public  class ResponseVo<T>{
	private String rspCode;
	private String rspMsg;

	@JSONField(serialize = false)
	private T tdata;

	@JSONField(serialize = false)
	public T getObjdData(){
		return this.tdata;
	}

	private JSONObject data;

	private List<JSONObject> dataList;

	public String getRspCode() {
		return rspCode;
	}
	public void setRspCode(String rspCode) {
		this.rspCode = rspCode;
	}
	public JSONObject getData() {
		return data;
	}
	public void setData(JSONObject data) {
		this.data = data;
	}

	public List<JSONObject> getDataList() {
		return dataList;
	}
	public void setDataList(List<JSONObject> dataList) {
		this.dataList = dataList;
	}

	public String getRspMsg() {
		return rspMsg;
	}

	public ResponseVo(){}
	
	/**
	 * 设置返回码和返回数据
	 * @param rspCode
	 * @param data
	 */
	public ResponseVo(String rspCode, JSONObject data) {
		
		this.rspCode = rspCode;
		this.rspMsg= AppRspCodeEnum.getRspMsg(rspCode);
		this.data = data;
	}

	/**
	 * 设置返回码和返回数据
	 * @param rspCode
	 * @param data
	 */
	public ResponseVo(String rspCode, List<JSONObject> data) {

		this.rspCode = rspCode;
		this.rspMsg= AppRspCodeEnum.getRspMsg(rspCode);
		this.dataList = data;
	}

	/**
	 * 将map作为返回的data
	 * @param rspCode
	 * @param map
	 */
	public ResponseVo(String rspCode, Map<String,Object> map)
	{
		this.rspCode = rspCode;
		this.rspMsg=AppRspCodeEnum.getRspMsg(rspCode);
		this.data= JSONObject.parseObject(JSONObject.toJSONString(map));
	}

	public ResponseVo(String rspCode, T t)
	{
		this.rspCode = rspCode;
		this.rspMsg=AppRspCodeEnum.getRspMsg(rspCode);

		this.data= JSONObject.parseObject(JSONObject.toJSONString(t));
		this.tdata=t;
	}

	public ResponseVo(String rspCode,String rspMsg)
	{
		this.rspMsg = rspMsg;
		this.rspCode = rspCode;
	}

	public ResponseVo(String rspCode,String rspMsg,JSONObject data)
	{
		this.rspMsg = rspMsg;
		this.rspCode = rspCode;
		this.data = data;
	}


	/**
	 * 设置返回码
	 * @param rspCode
	 */
	public ResponseVo(String rspCode) {
		this.rspCode = rspCode;
		this.rspMsg=AppRspCodeEnum.getRspMsg(rspCode);
	}

}
